#登录输入账户密码

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By


class LoginManager:
    def __init__(self, game_login_url, username, password):
        self.game_login_url = game_login_url
        self.username = username
        self.password = password

    def login(self):
        options = Options()
        driver = webdriver.Chrome(options=options)
        driver.set_window_size(1200, 768)
        try:
            driver.get(self.game_login_url)
            time.sleep(5)
            username_field = driver.find_element(By.NAME, "name")
            username_field.send_keys(self.username)
            time.sleep(1)

            password_field = driver.find_element(By.NAME, "password")
            password_field.send_keys(self.password)
            time.sleep(1)

            login_button = driver.find_element(By.CSS_SELECTOR, "button[type='submit']")
            login_button.click()
            time.sleep(3)

            login_url = driver.current_url
            print("登录成功")
            print("当前登录URL：", login_url)

            return driver

        except Exception as e:
            print("登录失败，错误信息：", e)
            driver.quit()
            return None




